package com.fourth.controller.api;

import com.fourth.dao.BusinessDao;
import com.fourth.dao.SortDao;
import com.fourth.service.BusinessService;
import com.fourth.service.GoodsService;
import com.fourth.vo.GoodVo;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Goods;
import com.ljx.entity.Sort;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoZhu
 * @version 1.0
 * @date 2023/2/28 14:25
 */
@Api(value = "commodity/api/goods", tags = {""})
@RestController
@RequestMapping("commodity/api/goods")
public class ApiGoodsController {

    @Autowired
    private BusinessService businessService;

    @Autowired
    private GoodsService goodsService;

    @Autowired(required = false)
    private SortDao sortDao;

    @Autowired(required = false)
    private BusinessDao businessDao;

    /**
     * 查询全部商品信息
     * @param currentPage
     * @param pageSize
     * @param goodVo
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "GoodVo", name = "goodVo", value = "", required = true)
    })
    @ApiOperation(value = "查询全部商品信息", notes = "查询全部商品信息", httpMethod = "POST")
    @PostMapping("/select")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody GoodVo goodVo
            ){

        System.out.println("goodVo = " + goodVo);
       return goodsService.selectByPage(currentPage,pageSize,goodVo);
    }

    /**
     * 修改审核信息
     * @param goods
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Goods", name = "goods", value = "", required = true)
    })
    @ApiOperation(value = "修改审核信息", notes = "修改审核信息", httpMethod = "POST")
    @PostMapping("/updateById")
    @ResponseBody
    public Result update(@RequestBody Goods goods){
            System.out.println("deposit = " + goods);
        boolean b = goodsService.updateById(goods);
        if (b == true){
                return new Result(200,"修改成功");
            }else {
                return new Result(500, "修改失败");
            }
    }

    /**
     * 类别搜索框
     * @return
     */
    @ApiOperation(value = "类别搜索框", notes = "类别搜索框")
    @RequestMapping("sort/findAllSort")
    public Result findSort(){
        List<Sort> list = sortDao.selectList(null);
        return new Result(2000,"查询成功",list);
    }

    /**
     * 店铺搜索框
     * @return
     */
    @ApiOperation(value = "店铺搜索框", notes = "店铺搜索框")
    @RequestMapping("business/selectshop")
    public Result selectshop(){

        List<BusinessInfo> businessInfos = businessDao.selectList(null);
        return new Result(2000,"查询成功",businessInfos);
    }
}
